package summary;

import java.util.Arrays;

/**
 * @Author: 海琳琦
 * @Date: 2022/8/30 10:23
 */
public class Title238 {

    public static int[] productExceptSelf(int[] nums) {
        int n = nums.length;
        int[] result = new int[n];
        Arrays.fill(result, 1);
        //前缀乘积，后缀乘积
        int left = 1, right = 1;
        for (int i = 0; i < n; i++) {
            //result = 前缀乘积*后缀乘积
            result[i] *= left;
            left *= nums[i];
            result[n - i - 1] *= right;
            right *= nums[n - i - 1];
        }
        return result;
    }

    public static void main(String[] args) {
        productExceptSelf(new int[]{1, 2, 3, 5});
    }
}
